<?php

use backend\widgets\JsBlock;
use backend\assets\plugins\LayerAsset;
use backend\assets\plugins\ICheckAsset;
use yii\web\JqueryAsset;
use kartik\grid\GridView;
use kartik\grid\CheckboxColumn;
use backend\grid\ActionColumn;
use backend\grid\DateColumn;
use backend\grid\SortColumn;
use backend\widgets\Bar;

JqueryAsset::register($this);
LayerAsset::register($this);
ICheckAsset::register($this);


/* @var $this yii\web\View */
/* @var $searchModel backend\models\ArticleCategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title                   = "Category";
$this->params['breadcrumbs'][] = yii::t('app', 'Category');
?>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <div class="ibox-content">
                <div class="row">
                    <div class="col-sm-4 m-b-sm" style="line-height: 2.3;">
                        <?= Bar::widget(['template' => '{create} {delete} {refresh} {view} {comment}']); ?>
                    </div>
                    <div class="col-sm-8 pull-right text-right">
                        <!--                            --><?php //echo $this->render('_search', ['model' => $searchModel]); ?>
                    </div>

                </div>
                <?
                $layout = <<<HTML
            <div class="row">
                <div class="table-responsive">{items}</div>
            </div>
            <div class="row">
              <div class="col-sm-4 text-right pull-right " style="line-height: 2.3;">{pager}{summary}</div>
            </div>
HTML;
                echo GridView::widget(
                    [
                        'dataProvider'   => $dataProvider,
                        'pager'          => ['options' => ['class' => 'pagination pull-right col-sm m-l', 'tag' => 'div']],
                        'summaryOptions' => ['class' => 'h5 m-r', 'tag' => 'span'],
                        'layout'         => $layout,
                        'tableOptions'   => ['class' => 'table table-striped '],
                        'columns'        => [
                            [
                                'class' => CheckboxColumn::className(),
                            ],
                            [
                                'attribute' => 'id',
                            ],
                            [
                                'attribute' => 'name',
                                'label'     => yii::t('app', 'Name'),
                                'format'    => 'html',
                                'value'     => function ($model, $key, $index, $column) {
                                    return str_repeat('--', $model['depth']).$model['name'];
                                },
                            ],
                            [
                                'attribute' => 'alias',
                                'label'     => yii::t('app', 'Alias'),
                            ],
                            [
                                'class' => SortColumn::className(),
                                'label' => yii::t('app', 'Sort'),
                            ],
//                            [
//                                'class'     => DateColumn::className(),
//                                'label'     => yii::t('app', 'Created At'),
////                                'format'    => 'datetime',
//                                'attribute' => 'created_at',
//                            ],
//                            [
//                                'class'     => DateColumn::className(),
//                                'label'     => yii::t('app', 'Updated At'),
////                                'format'    => 'datetime',
//                                'attribute' => 'updated_at',
//                            ],
                            [
                                'class'    => ActionColumn::className(),
                                'template' => '{create} {view} {update} {delete}',
                            ],
                        ],
                    ]
                );
                ?>
            </div>
        </div>
    </div>
</div>
<?php JsBlock::begin() ?>
<script>
  $(document).on('pjax:send', function () {
    layer.load(2)//pjax链接点击后显示加载动画；
  })
  $(document).on('pjax:complete', function () {
    layer.closeAll('loading')//pjax链接加载完成后隐藏加载动画；
    iCheck()//pjax加载完成之后调用重载多说函数
  })

  $(document).ready(function () {
    iCheck()
  })

  var iCheck = function () {
    $('input[name=\'selection[]\'],[name=\'selection_all\']').iCheck({
      handle: 'checkbox',
      checkboxClass: 'icheckbox_square-green ',
      radioClass: 'iradio_square-green',
    })
    //全选
    $('.select-on-check-all').on('ifChecked', function (event) {
      $('input[name=\'selection[]\']').iCheck('check')
    })
    //反选
    $('.select-on-check-all').on('ifUnchecked', function (event) {
      $('input[name=\'selection[]\']').iCheck('uncheck')
    })
  }
</script>
<?php JsBlock::end() ?>
